package com.cmcc.linlaker.ui.upload.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cmcc.linlaker.R;
import com.cmcc.linlaker.application.LinhuApp;
import com.cmcc.linlaker.ui.upload.bean.CheckingTaskBean;
import com.cmcc.linlaker.ui.upload.bean.PlanBean;

import java.util.List;

public class PlanAdapter extends RecyclerView.Adapter<PlanAdapter.ViewHolder> {

    private List<PlanBean.PlanData> itemList;
    private Context mContext;

    public PlanAdapter(Context mContext, List<PlanBean.PlanData> itemList) {
        this.itemList = itemList;
        this.mContext = mContext;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.plan_item, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        PlanBean.PlanData item = itemList.get(position);

        holder.text_name.setText(item.name);
        if (item.project != null) {
            holder.text_project_name.setText("所属项目：" + item.project.name);
        } else {
            holder.text_project_name.setText("");
        }

        holder.text_content.setText(item.description);
        holder.text_fzr.setText(item.user.userName);
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public int getItemCount() {
        return itemList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        public TextView text_name, text_project_name, text_content;
        public TextView text_fzr;

        public ViewHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(this);

            text_name = itemView.findViewById(R.id.text_name);
            text_project_name = itemView.findViewById(R.id.text_project_name);
            text_content = itemView.findViewById(R.id.text_content);

            text_fzr = itemView.findViewById(R.id.text_fzr);
        }

        @Override
        public void onClick(View v) {
        }
    }

}

